package com.cv.system.controller.system.user;

import com.cv.framework.common.pojo.Result;
import com.cv.system.controller.system.user.vo.profile.UserProfilePasswordReqVO;
import com.cv.system.controller.system.user.vo.profile.UserProfileRespVO;
import com.cv.system.controller.system.user.vo.profile.UserProfileSaveReqVO;
import com.cv.system.service.user.SystemUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import static com.cv.framework.common.pojo.Result.success;
import static com.cv.framework.security.core.utils.SecurityFrameworkUtil.getLoginUserId;

/**
 * 后台管理系统 - 用户个人中心
 *
 * @author Charles_XDXD
 */
@Tag(name = "后台管理系统 - 用户个人中心")
@RestController
@RequestMapping("/system/user/profile")
@Validated
@Slf4j
public class SystemUserProfileController {

    @Resource
    private SystemUserService systemUserService;

    @GetMapping("/get")
    @Operation(summary = "获得登录用户信息")
    public Result<UserProfileRespVO> getUserProfile() {
        return success(systemUserService.getUserProfile(getLoginUserId()));
    }

    @PutMapping("/update")
    @Operation(summary = "修改用户个人信息")
    public Result<Boolean> updateUserProfile(@Valid @RequestBody UserProfileSaveReqVO reqVO) {
        systemUserService.updateUserProfile(getLoginUserId(), reqVO);
        return success(true);
    }

    @PutMapping("/update-password")
    @Operation(summary = "修改用户个人密码")
    public Result<Boolean> updateUserProfilePassword(@Valid @RequestBody UserProfilePasswordReqVO reqVO) {
        systemUserService.updateUserProfilePassword(getLoginUserId(), reqVO);
        return success(true);
    }

}
